package com.h3c.nem.controller;


import com.alibaba.fastjson.JSONObject;
import com.eos.common.domain.ActiveUser;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.h3c.nem.dto.PsaDataDTO;
import com.h3c.nem.dto.PsaTbTrainClassDTO;
import com.h3c.nem.dto.PsaTbTrainWorkerDTO;
import com.h3c.nem.entity.TbTrainWorker;
import com.h3c.nem.service.ITbTrainClassService;
import com.h3c.nem.dto.TbTrainClassDTO;
import com.h3c.nem.utils.ReturnCodeData;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;

import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TbTrainClass 接口
 *
 * @Author: j26296
 * @Date: 2022-06-20
 * Description: tb_train_class controller
 * Version: 1.0
 * Copyright (C), 2022-2022, h3c
 */
@RestController
@CrossOrigin
@Slf4j
@RequestMapping(value = "/tbTrainClass",produces = "application/json;charset=utf-8")
public class TbTrainClassController {

    @Resource
    private ITbTrainClassService tbTrainClassService;
    /*
     *//**
     * @title: queryFuzzyListForPage
     * @description: 列表分页模糊查询
     * @params: [ paramsDTO, currentPage, pageSize ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*
    @RequestMapping(value = "/queryFuzzyListForPage", method = RequestMethod.GET)
    public ResponseEntity queryFuzzyListForPage(@ModelAttribute TbTrainClassDTO paramsDTO,
                                                            @RequestParam(name = "currentPage", required = true) Integer currentPage,
                                                            @RequestParam(name = "pageSize", required = true) Integer pageSize) {
        log.info("准备执行  列表分页模糊查询，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //分页
        Page page = PageHelper.startPage(currentPage, pageSize);
        //执行
        List<TbTrainClassDTO> resultDTOList = tbTrainClassService.selectFuzzyByDto(paramsDTO);
        PageInfo<TbTrainClassDTO> pageInfo = page.toPageInfo();
        pageInfo.setList(resultDTOList);
        log.info("执行列表分页模糊查询完成，准备返回的结果为：" + JSON.toJSONString(pageInfo));
        return ResponseEntity.success("列表分页模糊查询成功", pageInfo);
    }

    *//**
     * @title: queryListForPage
     * @description: 列表分页精确查询
     * @params: [ paramsDTO, currentPage, pageSize ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*
    @RequestMapping(value = "/queryListForPage", method = RequestMethod.GET)
    public ResponseObject queryListForPage(@ModelAttribute TbTrainClassDTO paramsDTO,
                                                       @RequestParam(name = "currentPage", required = true) Integer currentPage,
                                                       @RequestParam(name = "pageSize", required = true) Integer pageSize) {
        log.info("准备执行  列表分页查询，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //分页
        Page page = PageHelper.startPage(currentPage, pageSize);
        //执行
        List<TbTrainClassDTO> resultDTOList = tbTrainClassService.selectFuzzyByDto(paramsDTO);
        PageInfo<TbTrainClassDTO> pageInfo = page.toPageInfo();
        pageInfo.setList(resultDTOList);
        log.info("执行列表分页查询完成，准备返回的结果为：" + JSON.toJSONString(pageInfo));
        return ResponseObject.success("列表分页查询成功", pageInfo);
    }


    *//**
     * @title: save
     * @description: 数据插入
     * @params: [ paramsDTO ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResponseObject save(@RequestBody TbTrainClassDTO paramsDTO) {
        log.info("准备执行 数据插入，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //执行
        Integer result = tbTrainClassService.insertDto(paramsDTO);
        log.info("执行 数据插入完成，准备返回的结果为：" + JSON.toJSONString(result));
        return ResponseObject.success("数据插入成功", result);
    }

    *//**
     * @title: update
     * @description: 数据修改
     * @params: [ paramsDTO ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseObject update(@RequestBody TbTrainClassDTO paramsDTO) {
        log.info("准备执行 数据修改，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //执行
        Integer result = tbTrainClassService.updateDto(paramsDTO);
        log.info("执行 数据修改完成，准备返回的结果为：" + JSON.toJSONString(result));
        return ResponseObject.success("数据修改成功", result);
    }

    */

    /**
     * @title: delete
     * @description: 数据删除
     * @params: [ id ]
     * @return: org.springframework.http.ResponseEntity
     * @createTime: 2022-06-20
     * @version: 1.0
     * @author: j26296
     *//*
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ResponseObject delete(@RequestBody TbTrainClassDTO paramsDTO) {
        log.info("准备执行 数据删除，传入的参数为：" + JSON.toJSONString(paramsDTO));
        //执行
        Integer result = tbTrainClassService.deleteDto(paramsDTO);
        log.info("执行 数据删除 完成，准备返回的结果为：" + JSON.toJSONString(result));
        return ResponseObject.success("数据删除", result);
    }*/
    @ApiOperation(value = "pas发送一封信", notes = "pas发送一封信")
    @RequestMapping(value = "/syncPsaAndSendTodoTask", method = RequestMethod.POST)
    public ResponseEntity<JSONObject> syncPsaAndSendTodoTask(@RequestBody PsaTbTrainClassDTO psaDataDTO) {
        log.info("准备执行 数据插入，传入的参数为：" + JSON.toJSONString(psaDataDTO));
        JSONObject data = new JSONObject();
        try {
            //执行
            List<PsaTbTrainWorkerDTO> res = tbTrainClassService.syncPsaAndSendOneMail(psaDataDTO);
            data.put("data",res);
            data.put("msg", "数据插入成功");
            data.put("code", ReturnCodeData.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("执行 数据插入 异常，异常信息为：" + JSON.toJSONString(e));
            data.put("msg", e.toString());
            data.put("code", ReturnCodeData.FAIL);
        }
        log.info("执行 数据插入完成，准备返回的结果为：" + JSON.toJSONString(data));
        return new ResponseEntity<>(data, HttpStatus.ACCEPTED);
    }
}
